package com.test.employeedemo.dao;

import com.test.employeedemo.bean.Employee;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/9/9 20:27
 */
public class Dao {
    private static Map<Integer, Employee> emps = new LinkedHashMap<>();

    static {
        emps.put(1001, new Employee(1001, "aa", "bb", "aa@123.com"));
        emps.put(1002, new Employee(1002, "cc", "dd", "cc@123.com"));
        emps.put(1003, new Employee(1003, "ee", "ff", "ee@123.com"));
        emps.put(1004, new Employee(1004, "gg", "hh", "gg@123.com"));
        emps.put(1005, new Employee(1005, "ii", "kk", "ii@123.com"));
    }

    public List<Employee> getEmployees() {
        return new ArrayList<>(emps.values());
    }

    public Employee getEmployeeById(Integer id) {
        return emps.get(id);
    }

    public void delete(Integer id) {
        emps.remove(id);
    }

    public void save(Employee emp) {
        long time = System.currentTimeMillis();
        emp.setEmployeeId((int) time);
        emps.put(emp.getEmployeeId(), emp);
    }

    public void update(Employee emp) {
        emps.put(emp.getEmployeeId(), emp);
    }
}
